<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!-- 3、模拟随机发放水果功能，水果品种固定，每次之发放一种并输出您获得的水果是XX-->
    <h1>开始发水果了</h1>
    <input type="button" value="点击按钮随机分配" onclick="allot()">
    <p>恭喜你，获得了<span id="fruit" style="color: red">苹果</span></p>
    <script>
        function allot() {
            var fruits=new Array("苹果","香蕉","梨子","西瓜","葡萄","哈密瓜","火龙果");
            var num=Math.ceil(Math.random()*7)-1;
            document.getElementById("fruit").innerHTML=fruits[num];
        }
    </script>
</body>
</html>